/**
 * Copyright (C) 2006 OQube 
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *  
 * author: Arnaud Bailly - abailly AT oqube DOT com
 * created: 14 juin 2006
 */
package speculoos.jndi.mappers;

import java.util.Map;

import speculoos.core.Mapper;
import speculoos.core.MapperException;
import speculoos.utils.VariableString;

/**
 * A mapper that updates passed environment by instantiating some
 * {@see speculoos.utils.VariableString} object.
 * 
 * @author nono
 * 
 */
public class StringVariable implements Mapper {

	private VariableString var;

	private String reference;

	/**
	 * 
	 * @param string a variable name
	 * @param filter a valid filter
	 */
	public StringVariable(String string, VariableString filter) {
		this.reference = string;
		this.var = filter;
	}

	/**
	 * @return Returns the reference.
	 */
	public String getReference() {
		return reference;
	}

	/**
	 * @param reference
	 *            The reference to set.
	 */
	public void setReference(String reference) {
		this.reference = reference;
	}

	/**
	 * @return Returns the var.
	 */
	public VariableString getVar() {
		return var;
	}

	/**
	 * @param var
	 *            The var to set.
	 */
	public void setVar(VariableString var) {
		this.var = var;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see speculoos.core.Mapper#map(java.lang.Object, java.util.Map)
	 */
	public Object map(Object input, Map param) throws MapperException {
		String v = var.instance(param);
		param.put(reference, v);
		return input;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see speculoos.core.Mapper#getName()
	 */
	public String getName() {
		return "FilterEnvironment: " + reference;
	}

}
